#include "VulkanDescriptorSets.h"

#include "Runtime/Misc/Crc.h"

namespace Alice
{
    template void FVulkanDescriptorSetsLayoutInfo::FinalizeBindings<true>(const VulkanDevice& Device, const FUniformBufferGatherInfo& UBGatherInfo, const CGISamplerState* ImmutableSamplers, bool bUsesBindless);
    template void FVulkanDescriptorSetsLayoutInfo::FinalizeBindings<false>(const VulkanDevice& Device, const FUniformBufferGatherInfo& UBGatherInfo, const CGISamplerState* ImmutableSamplers, bool bUsesBindless);
    void FVulkanDescriptorSetsLayoutInfo::GenerateHash(const CGISamplerState* InImmutableSamplers, VkPipelineBindPoint InBindPoint)
    {
        /*const int32 LayoutCount = SetLayouts.Num();
        Hash = Crc::MemCrc32(&TypesUsageID, sizeof(uint32), LayoutCount);

        for (int32 layoutIndex = 0; layoutIndex < LayoutCount; ++layoutIndex)
        {
            SetLayouts[layoutIndex].GenerateHash();
            Hash = Crc::MemCrc32(&SetLayouts[layoutIndex].Hash, sizeof(uint32), Hash);
        }

        const uint32 NumStages = GetNumStagesForBindPoint(InBindPoint);
        for (uint32 RemapingIndex = 0; RemapingIndex < NumStages; ++RemapingIndex)
        {
            const FStageInfo& StageInfo = StageInfos[RemapingIndex];

            Hash = Crc::TypeCrc32(StageInfo.PackedGlobalsSize, Hash);
            Hash = Crc::TypeCrc32(StageInfo.NumBoundUniformBuffers, Hash);
            Hash = Crc::TypeCrc32(StageInfo.NumImageInfos, Hash);
            Hash = Crc::TypeCrc32(StageInfo.NumBufferInfos, Hash);
            Hash = Crc::TypeCrc32(StageInfo.NumAccelerationStructures, Hash);

            const TArray<VkDescriptorType>& Types = StageInfo.Types;
            Hash = FCrc::MemCrc32(Types.GetData(), sizeof(VkDescriptorType) * Types.Num(), Hash);
        }

        // It would be better to store this when the object is created, but it's not available at that time, so we'll do it here.
        BindPoint = InBindPoint;

        // Include the bind point in the hash, because we can have graphics and compute PSOs with the same descriptor info, and we don't want them to collide.
        Hash = Crc::MemCrc32(&BindPoint, sizeof(BindPoint), Hash);*/
        Hash=100;
    }
    template<bool bIsCompute>
    void FVulkanDescriptorSetsLayoutInfo::FinalizeBindings(const VulkanDevice& inDevice, const FUniformBufferGatherInfo& UBGatherInfo, const CGISamplerState* ImmutableSamplers, bool bUsesBindless)
    {
        GenerateHash(ImmutableSamplers, bIsCompute ? VK_PIPELINE_BIND_POINT_COMPUTE : VK_PIPELINE_BIND_POINT_GRAPHICS);
    }
}
